package com.coffee.ws.command;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: songkui
 * @since: 2023/2/22 16:24
 */
@Slf4j
public class CommandModelMapping {

    private static final Map<Integer, CommandModel> commandModelMap = new HashMap<>();
    private CommandModelMapping() {
    }

    public static CommandModel getCommandModel(Integer cmd) {
        if (commandModelMap.isEmpty()) {
            log.error("CMD -> CommandModelMap  is null !");
            return null;
        } else {
            return commandModelMap.get(cmd);
        }
    }

    public static void initializeCommandModel(Map<Integer, CommandModel> commandMap) throws Exception {
        if (null != commandMap) {
            commandModelMap.putAll(commandMap);
            log.info("CommandMapping size: {}", commandModelMap.size());
        }else {
            throw new Exception("Coffee websocket not command");
        }
    }



}
